<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title></title>
    <link href="/resource/css/index3.css" rel="stylesheet">
    <script type="text/javascript" src="/resource/js/jquery-3.2.1.js"></script>
    <script type="text/javascript" src="/resource/My97DatePicker/WdatePicker.js"></script>
</head>
<body>
    <form>
        <table>
            <tr>
                <td>财务日期:</td>
                <td><input type="date" name="caiwutime" onblur="blur1()">
                   <span id="sp1"></span>
                </td>
                <td></td>
                <td></td>
                <td></td>

            </tr>
            <tr>
                <td>源账号名称:</td>
                <td><input type="text" name="yuanname" onblur="blur2()">
                    <span id="sp2"></span>
                </td>
                <td>源账号:
                  <input type="hidden" name="yuanzhanghao">
                </td>
                <td><span id="sp3"></span></td>
                <td></td>
            </tr>
            <tr>
                <td>目标账号名称:</td>
                <td><input type="text" name="mvbiaoname" onblur="blur3()">
                    <span id="sp4"></span>
                </td>
                <td>目标账号:<input type="hidden" name="mvbiaozhanghao"></td>
                <td><span id="sp5"></span></td>
                <td></td>
            </tr>
            <tr>
                <td>科目编号:</td>
                <td><input type="text" name="kemvbianhao" onblur="blur4()">
                    <span id="sp6"></span>
                </td>
                <td>科目</td>
                <td><input type="text" name="kemv" onblur="blur5()">
                    <span id="sp7"></span></td>
                <td></td>
            </tr>
            <tr>
                <td>借方:</td>
                <td><input type="text" name="jiefang" onblur="blur6()"><span id="sp8"></span> </td>
                <td>贷方:</td>
                <td><input type="text" name="daifang" onblur="blur6()"><span id="sp9"></span> </td>
                <td>余额:<span id="sp10"></span></td>

            </tr>
            <tr>
                <td>摘要:</td>
                <td><input type="text" name="zhaiyao" onblur="blur8()"><span id="sp11"></span> </td>
                <td></td><td></td><td></td>
            </tr>
            <tr>
                <td colspan="5">
                    <button onclick="tj()">提交</button>
                </td>
            </tr>
        </table>
    </form>

<script>
     function yzhn(){
         var yuanname =$("[name='yuanname1']").val();
         $.post("selectyuanname",{yuanname:yuanname},function(msg){
             for(var i in msg){
                 $("[name='yuanname']").val(msg[i].yuanname);
                 $("#sp3").val(msg[i].yuanzhanghao)
                 $("[name='yuanzhanghao']").val(msg[i].yuanzhanghao);
             }
         })
     }
     var flag =true;
     function blur1(){

        var caiwu=$("[name='caiwutime']").val();
        if(caiwu!=''){
            $("#sp1").html('')
        }else{
            flag=false;
            $("#sp1").html('<font color="red">财务时间不能为空</font>')
        }
     }
     function blur2(){

         var yuanname=$("[name='yuanname']").val();
         if(yuanname!=''){
             $("#sp2").html('')
         }else{
             flag=false;
             $("#sp2").html('<font color="red">源名称不能为空</font>')
         }
     }
     function blur3(){
         var mvbiaoname=$("[name='mvbiaoname']").val();
         if(mvbiaoname!=''){
             $("#sp4").html('')
         }else{
             flag=false;
             $("#sp4").html('<font color="red">目标编号不能为空</font>')
         }
     }
     function blur4(){
         var kemvbianhao=$("[name='kemvbianhao']").val();
         if(kemvbianhao!=''){
             $("#sp6").html('')
         }else{
             flag=false;
             $("#sp6").html('<font color="red">科目编号不能为空</font>')
         }
     }
     function blur5(){
         var kemv=$("[name='kemv']").val();
         if(kemv!=''){
             $("#sp7").html('')
         }else{
             flag=false;
             $("#sp7").html('<font color="red">科目不能为空</font>')
         }
     }

     function blur6(){
         var jiefang=$("[name='jiefang']").val();
         var daifang=$("[name='daifang']").val();
         if(jiefang!=''||daifang!=''){
             $("#sp8").html('')
             var yue=jiefang-daifang;
             $("#sp10").html(yue);

         }else{
             flag=false;
             $("#sp8").html('<font color="red">不能为空</font>')
         }
     }
     function blur8(){
         var zhaiyao=$("[name='zhaiyao']").val();
         if(zhaiyao!=''){
             $("#sp11").html('')
         }else{
             flag=false;
             $("#sp11").html('<font color="red">目标编号不能为空</font>')
         }
     }


     if(flag){
         function tj(){
             $.ajax({
                 type:"post",
                 data:$("form").serialize(),
                 url:"add",
                 success:function(msg){
                     if(msg>0){
                         location="list";
                     }else{
                         location.reload();
                     }
                 }
             })
         }
     }

</script>
</body>


</html>